package o;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources.NotFoundException;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsConfig;
import java.lang.ref.WeakReference;

public class bla {
    private static volatile WeakReference<Context> ˊ;

    public static int ॱ(@Nullable Context context, @Nullable String str) {
        int i = 0;
        if (!(context == null || str == null)) {
            try {
                i = context.getPackageManager().getPackageInfo(str, 0).versionCode;
            } catch (NameNotFoundException e) {
                bkp.ॱ.ˏ("PackageManagerUtils", "NameNotFoundException: " + e);
            }
        }
        return i;
    }

    @NonNull
    public static String[] ˏ(@Nullable Context context, @Nullable String str) {
        if (context == null || str == null) {
            return new String[0];
        }
        try {
            return bkz.ˎ(context.getPackageManager().getPackageInfo(str, 0).splitNames);
        } catch (NameNotFoundException e) {
            bkp.ॱ.ˏ("PackageManagerUtils", "NameNotFoundException: " + e);
            return new String[0];
        }
    }

    public static boolean ˋ(@Nullable Context context, @Nullable String str) {
        boolean z = false;
        if (!(context == null || str == null)) {
            try {
                ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(str, DnsConfig.MAX_CACHE_ENTRIES);
                if (applicationInfo.metaData != null) {
                    z = applicationInfo.metaData.getBoolean("com.android.vending.splits.required");
                }
            } catch (NameNotFoundException e) {
                bkp.ॱ.ˏ("PackageManagerUtils", "NameNotFoundException: " + e);
            }
        }
        return z;
    }

    @NonNull
    public static String ˎ(@NonNull Context context, @NonNull String str) {
        try {
            PackageManager packageManager = context.getPackageManager();
            str = packageManager.getApplicationInfo(str, 0).loadLabel(packageManager).toString();
        } catch (NameNotFoundException e) {
            bkp.ॱ.ˊ("PackageManagerUtils", "Exception when reading application label: " + e);
        } catch (Exception e2) {
            bkp.ॱ.ˊ("PackageManagerUtils", "Exception when reading application label: " + e2);
        }
        return str;
    }

    @NonNull
    private static Context ˊ(@NonNull Context context, @NonNull String str) throws NameNotFoundException {
        Context context2;
        if (ˊ != null) {
            context2 = (Context) ˊ.get();
            if (context2 != null && str.equals(context2.getPackageName())) {
                return context2;
            }
        }
        context2 = context.createPackageContext(str, 2);
        ˊ = new WeakReference(context2);
        return context2;
    }

    @NonNull
    public static String ˎ(@NonNull Context context, @NonNull String str, @StringRes int i) {
        try {
            return ˊ(context, str).getResources().getString(i);
        } catch (NameNotFoundException e) {
            bkp.ॱ.ˊ("PackageManagerUtils", "Exception when reading string resource: " + e);
            return "";
        } catch (NotFoundException e2) {
            bkp.ॱ.ˊ("PackageManagerUtils", "Exception when reading string resource: " + e2);
            return "";
        } catch (Exception e3) {
            bkp.ॱ.ˊ("PackageManagerUtils", "Exception when reading string resource: " + e3);
            return "";
        }
    }
}
